package com.nf.controller;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/dologin")
public class LoginViewServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username=req.getParameter("username");//申明变量
        String pwd= req.getParameter("pwd");
        if ("123".equals(username)&&"123".equals(pwd)){//设置账号密码
            HttpSession session=req.getSession();//调用会话
            session.setAttribute("user",username);//给到会话里面
            resp.sendRedirect("/list");//重定向查询全部页面
        }else {
            req.getRequestDispatcher("/WEB-INF/nologin.jsp").forward(req,resp);//转发到登录失败页面
        }
    }
}
